<?php
namespace app\api\controller;
use app\user\controller\User;
use think\Db;
class Hwled
{
	public function cwszinfo(){
		$townsid=input('townsid');
		if($townsid){


			$info=Db::name('Sbalance')->where('townsid',$townsid)->field('year,month,townsid')->group('year,month,townsid')->select();
			$nums=0;
			if($info){
				foreach ($info as $key => $value) {
					$nums++;
					$infos[$key]['srprices']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('debit');
					$infos[$key]['zcprices']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('credit');
					$infos[$key]['syjieyu']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('initbalance');
					$infos[$key]['byjieyu']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('endbalance');
					$infos[$key]['title']=get_alltowns($townsid).$value['year'].'年'.$value['month'].'月财务公示';

					$infol=Db::name('proof')->where(['townsid' =>$townsid ,'year'=>$value['year'],'month'=>$value['month'] ])->order('id DESC')->select();
					if($infol){
						$infos[$key]['mingxi']=$infol;
					}else{
						$infos[$key]['mingxi']=null;
					}

					unset($infol);
				}
				$data['status']=1;
				$data['nums']=$nums;
				$data['info']=$infos;

			}else{
				$data['status']=0;
				$data['info']='无数据';
			}

		}else{
			$data['status']=0;
			$data['info']='无村镇参数';
		}
		return  json($data);
	}
	public function cwszinfo1(){
		$townsid=input('townsid');
		if($townsid){


			$info=Db::name('Sbalance')->where('townsid',$townsid)->field('year,month,townsid')->group('year,month,townsid')->order('year DESC,month DESC')->limit(1)->select();
			$nums=0;
			if($info){
				foreach ($info as $key => $value) {
					$nums++;
					$infos[$key]['srprices']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('debit');
					$infos[$key]['zcprices']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('credit');
					$infos[$key]['syjieyu']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('initbalance');
					$infos[$key]['byjieyu']=Db::name('Sbalance')->where('townsid','=',$townsid)->where('year','=',$value['year'])->where('month','=',$value['month'])->sum('endbalance');
					$infos[$key]['title']=get_alltowns($townsid).$value['year'].'年'.$value['month'].'月财务公示';

					$infol=Db::name('proof')->where(['townsid' =>$townsid ,'year'=>$value['year'],'month'=>$value['month'] ])->order('id DESC')->select();
					if($infol){
						foreach ($infol as $key1=>$value1){
							$infol[$key1]['ndate']=time_yueri($value1['ndate']);
							if($value1['debitamount']>0){
								$infol[$key1]['leixing']=1;
							}else{
								$infol[$key1]['leixing']=2;
							}

						}
						$infos[$key]['mingxi']=$infol;

					}else{
						$infos[$key]['mingxi']=null;
					}

					unset($infol);
				}
				$data['status']=1;
				$data['nums']=$nums;
				$data['info']=$infos;

			}else{
				$data['status']=0;
				$data['info']='无数据';
			}

		}else{
			$data['status']=0;
			$data['info']='无村镇参数';
		}
		return  json($data);
	}

	public function Jcopeninfo(){
		$townsid=input('townsid');
		if($townsid){
			$info=Db::name('Jcopen')->where(['townsid' =>$townsid])->order('id DESC')->limit(10)->select();
			$nums=0;
			if($info){

				foreach ($info as $key => $value) {
					$infos[$key]['title']=$value['title'];

					$infos[$key]['towns']=get_alltowns($value['townsid']);
					$infos[$key]['catname']=get_catname($value['bsid']);
					$infos[$key]['times']=time_nianyueri($value['create_time']);
					$infos[$key]['content']=$value['content'];
					//$infos[$key]['neirong']=str_replace(array('/public/static/uploads/editor/'),array('http://sanqingjw.gov.cn/public/static/uploads/editor/'),$value['content']);
					$nums++;
				}
				$data['nums']=$nums;
				$data['info']=$infos;
				$data['status']=1;
			}else{
				$data['status']=0;
				$data['info']='无数据';
			}
		}else{
			$data['status']=0;
			$data['info']='无村镇参数';
		}
		return  json($data);
	}

	public function townsinfo(){
		$info=Db::name('Towns')->where('pid','>',0)->select();
		if($info){
			foreach ($info as $key=>$value){
				$info[$key]['id']=$value['code'];
			}
			$daas['status']=1;
			$daas['info']=$info;
		}else{
			$daas['status']=0;
		}
		return json($daas);
	}
	public function api_tnames($id){
		if($id){
			$info=Db::name('Towns')->where('code',$id)->value('tname');
		}
		if($info){
			$datas['status']=1;
			$datas['tname']=$info;
		}else{
			$datas['status']=0;
		}
		return json($datas);
	}

}
